home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Tools for Macintosh
/
Power Tools for Macintosh (SoftBit)(1992).iso
/
Applications
/
Alpha 4.01
/
ACMDS
/
SndPlay.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-15
|
4KB
|
139 lines
/****************************************************************
* *
* SndPlay - play the named 'snd ' resource *
* *
* Copyright © 1990 Karl J. Smith. All Rights Reserved *
* *
* email: ksmith@jarthur.claremont.edu *
* *
* 8/13/90 *
* *
* Changes: *
* -------- *
* 8/15/90 KJS Now plays if it hits either end of *
* stream or a carriage return. *
* *
* When debugging, set the project type to application, *
* and add the ANSI project. *
* *
* When all your bugs are out, 'undef' DEBUG, set the project *
* type to Code Resource, with type = ACMD, name = <the name *
* of the function>, file type to 'AEXT', and the purgeable *
* flag set to true. *
* *
* Also, you need to remove the ANSI project from the ACMD *
* project and replace it with the ANSI-A4 project if you use *
* any functions in ANSI, such as strlen. *
* *
* If you are not using THINK C, I'm not quite sure what you *
* should do. :-) *
* *
****************************************************************/
/*
** This ACMD will attempt load and play (sequentially) all 'snd '
** resources that are listed in the input string, separated by
** '\r' characters. When a '\r' character is reached, the previous
** sound will be played (if possible).
*/
#undef DEBUG
#include <stdio.h>
#include <string.h>
/* Prototypes */
char *
#ifdef DEBUG
dummy(char *inStr);
#else DEBUG
main(char *inStr);
#endif DEBUG
char *
#ifdef DEBUG
dummy(inStr)
#else DEBUG
main(inStr)
#endif DEBUG
char *inStr;
{
char *currentChar;
Handle sndHandle;
Str255 soundName; /* Name of current sound to play */
char *currentCharOfName; /* used to create name of sound to play */
currentCharOfName = (char *)soundName;
for (currentChar = inStr; *currentChar != 0; currentChar++)
{
if ( (*currentChar == '\r') || (*(currentChar + 1L) == '\0'))
{
if ( (*(currentChar + 1L) == '\0') /* No return at end of line */
&& (*currentChar != '\r') )
{
*currentCharOfName++ = *currentChar;
}
/* Try to play the sound */
*currentCharOfName = '\0'; /* End of name */
CtoPstr((char *)soundName);
sndHandle = GetNamedResource('snd ', soundName);
if (sndHandle != NULL)
{
SndPlay(NULL, sndHandle, FALSE);
ReleaseResource(sndHandle);
DisposHandle(sndHandle);
}
currentCharOfName = (char *)soundName; /* Start at beginning of name */
}
else
{
*currentCharOfName++ = *currentChar;
}
}
return(inStr);
}
#ifdef DEBUG
char * ConvertRtoN(char *theStr);
char * ConvertRtoN(theStr)
char *theStr;
{
char *currentChar;
for (currentChar = theStr;*currentChar != 0; currentChar++)
if (*currentChar == '\r')
*currentChar = '\n';
}
main()
{
char *str = "Boing\rMonkey\r";
char *ret;
char once[255];
strcpy(once, str);
ret = dummy(once);
ConvertRtoN(ret); /* Convert '\r' to '\n' so we can see them in a printf */
ConvertRtoN(str);
printf("The original is:\n\n%s", str);
printf("\n----\n\nThe result is:\n\n%s", ret);
}
#endif DEBUG